package cn.gxa.edu_adm.dao.impl;

import cn.gxa.edu_adm.bean.Admin;
import cn.gxa.edu_adm.dao.AdminDao;
import cn.gxa.edu_adm.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {
    @Override
    public Admin checkLogin(String username, String password)  {
        String   sql="select  *  from  admin  where id=?  and  password=?";
        //查询对象
        QueryRunner  queryRunner=new QueryRunner(DruidUtils.getDruidDataSource());
        try {
            //执行查询语句
            return queryRunner.query(sql,new BeanHandler<Admin>(Admin.class),username,password);
        } catch (SQLException e) {
            e.printStackTrace();
            return  null;
        }
    }

    @Override
    public int updateHeadImg(Integer userId, String filePath) {
        String  sql="update admin set headImg=? where id=?";
        QueryRunner  queryRunner=new QueryRunner(DruidUtils.getDruidDataSource());
        try {
            return   queryRunner.update(sql,filePath,userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updatePassword(Integer userId, String oldPassword, String newPassword) {
        return 0;
    }
}
